package com.cooper.domain;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.cooper.entity.OrderAddress;
import com.cooper.entity.OrderInfo;
import com.cooper.entity.OrderItem;

/**
 * 订单聚合
* @Description: 
* @version: v1.0.0
* @author: tianlg
* @date: Mar 8, 2015 11:16:05 AM
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* Mar 8, 2015      tianlg          v1.0.0
 */
public class OrderEntry extends Entity implements Entry<OrderEntry>{

	private static final long serialVersionUID = 2233310127867564132L;

	private String orderNum;
	
	private OrderInfo orderInfo;
	private OrderAddress orderAddress;
	private List<OrderItem> orderItems = new ArrayList<OrderItem>();
	
	@Override
	public boolean saveIdentityAs(OrderEntry other) {
		return this.getOrderNum().equals(other.getOrderNum());
	}
	
	public void setOrderNumber(){
		if(StringUtils.isNotEmpty(this.orderNum)){
			this.orderInfo.setOrderNum(orderNum);
			this.orderAddress.setOrderNum(orderNum);
			
			for(OrderItem orderItem: orderItems){
				orderItem.setOrderNum(orderNum);
			}
		}
	}
	
	public void setOrderItem(int index, OrderItem orderItem){
		if(null != this.orderItems){
			this.orderItems.set(index, orderItem);
		}
	}

	public String getOrderNum() {
		return orderNum;
	}

	public void setOrderNum(String orderNum) {
		this.orderNum = orderNum;
	}

	public OrderInfo getOrderInfo() {
		return orderInfo;
	}

	public void setOrderInfo(OrderInfo orderInfo) {
		this.orderInfo = orderInfo;
	}

	public OrderAddress getOrderAddress() {
		return orderAddress;
	}

	public void setOrderAddress(OrderAddress orderAddress) {
		this.orderAddress = orderAddress;
	}

	public List<OrderItem> getOrderItems() {
		return orderItems;
	}

	public void setOrderItems(List<OrderItem> orderItemList) {
		this.orderItems = orderItemList;
	}

}
